<?php echo CHtml::form('/user/sendemails', 'post', array('id'=>'send-emails', 'onsubmit'=>'return validateEmailsForm()',))?>
	
	<?php //echo CHtml::hiddenField('dealId', $this->dealId)?>
	
	<div class="input-email" id="email-1">
		E-mail&nbsp;
		<?php echo CHtml::textField('emails[]', '', array('size'=>13, 'id'=>''))?>
		&nbsp;Имя&nbsp;
		<?php echo CHtml::textField('first_name[]', '', array('size'=>13, 'id'=>''))?>
		&nbsp;Фамилия&nbsp;
		<?php echo CHtml::textField('last_name[]', '', array('size'=>13, 'id'=>''))?>
    </div>
    <div class="input-email" id="email-2">
		E-mail&nbsp;
		<?php echo CHtml::textField('emails[]', '', array('size'=>13, 'id'=>''))?>
		&nbsp;Имя&nbsp;
		<?php echo CHtml::textField('first_name[]', '', array('size'=>13, 'id'=>''))?>
		&nbsp;Фамилия&nbsp;
		<?php echo CHtml::textField('last_name[]', '', array('size'=>13, 'id'=>''))?>
    </div>
    <div class="input-email" id="email-3">
		E-mail&nbsp;
		<?php echo CHtml::textField('emails[]', '', array('size'=>13, 'id'=>''))?>
		&nbsp;Имя&nbsp;
		<?php echo CHtml::textField('first_name[]', '', array('size'=>13, 'id'=>''))?>
		&nbsp;Фамилия&nbsp;
		<?php echo CHtml::textField('last_name[]', '', array('size'=>13, 'id'=>''))?>
		<?php echo CHtml::link('Добавить поле', 'javascript: void(0);', array(	'onclick'=>'addEmail()', 
    																		'class'=>'add-email', 
    																		'id'=>'add-email-link')) ?>
    </div>
    
    <?php echo CHtml::hiddenField('id-of-email', '3', array('id'=>'id-of-email'))?>
    
    <div class="input-button">
		<?php echo CHtml::submitButton(Yii::t('main', 'Отправить'))?>
	</div>

<?php echo Chtml::endForm()?>

<script type="text/javascript">

	function addEmail() {
		var div = $('#email-1').clone(); //insertBefore('#add-number-link');
		var id = ~~$("#id-of-email").val();
		div.attr("id", "email-"+(id+1)).insertBefore('#email-3');
//		div.attr("id", "email-number-"+(id+1)).insertBefore('#add-number-link');
		$("#id-of-email").val(id+1);
		$("#email-"+(id+1)+" input").val("");
		return false;
	}

	function validateEmailsForm() {
		result = '';
		$('input[name="emails[]"]').each(function(){
	        if($(this).val() != '') {
	        	result = true;
	        }
	    });
	    
		if(!result) {
			alert('<?php echo Yii::t('main', 'Укажите хотябы одинa e-mail')?>');
			return false;
		} else 
			return true;
	}	
		
</script>